using System.Web.Mvc;
using MvcCms.Service.Cache;
using MvcCms.Service;
using System.Linq;

using Microsoft.Practices.ServiceLocation;
using MvcCms.Web.ViewModels;

namespace MvcCms.Web.Controllers
{
    public class SiteMapController  : MvcCms.Service.Code.BaseClasses.MvcCmsControllerBase
    {
        public ActionResult Index()
        {
            var cacheService = ServiceLocator.Current.GetInstance<ICacheService>();
            ICmsService service = ServiceLocator.Current.GetInstance<ICmsService>();

            var baseUrl = cacheService.GetCurrentPortal().URLAuthority;
            var categories = service.ListAllCategoriesWithPages().Where(cat => cat.Portal.PortalID.Equals(cacheService.GetCurrentPortal().PortalID));

            var model = new SiteMapModel
            {
                _Categories = categories,
                _BaseUrl = baseUrl
            };

            return View("SiteMap", "DontUseMaster", model);
        }

    }
}
